<div class="dialog">
    <table>
        <tbody>

            <tr class="prop">
                <td valign="top" class="name">
                    <label for="serialNumber"><g:message code="purchase.serialNumber" default="Serial Number" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: purchaseInstance, field: 'serialNumber', 'errors')}">
                    <g:textField name="serialNumber" value="${fieldValue(bean: purchaseInstance, field: 'serialNumber')}" />

                </td>
       
                <td valign="top" class="name">
                    <label for="date"><g:message code="purchase.date" default="Date" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: purchaseInstance, field: 'date', 'errors')}">
                    <g:jqDatePicker name="date" value="${purchaseInstance?.date}"></g:jqDatePicker>
                </td>
        
                <td valign="top" class="name">
                    <label for="maker"><g:message code="purchase.maker" default="Maker" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: purchaseInstance, field: 'maker', 'errors')}">
                    <g:textField name="makerInput" value="${purchaseInstance?.maker?.encodeAsHTML()}"/>
                    <g:hiddenField name="maker.id" value="${purchaseInstance?.maker?.id}" />
                </td>
            </tr>
        
            <tr class="prop">
                <td valign="top" class="name">
                    <label for="dealer"><g:message code="purchase.dealer" default="Dealer" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: purchaseInstance, field: 'dealer', 'errors')}">
                    <g:textField name="dealerInput" value="${purchaseInstance?.dealer?.encodeAsHTML()}"/>
                    <g:hiddenField name="dealer.id" value="${purchaseInstance?.dealer?.id}" />
                 </td>
        
                <td valign="top" class="name">
                    <label for="director"><g:message code="purchase.director" default="Director" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: purchaseInstance, field: 'director', 'errors')}">
                    <g:textField name="directorInput" value="${purchaseInstance?.director?.encodeAsHTML()}"/>
                    <g:hiddenField name="director.id" value="${purchaseInstance?.director?.id}" />
                 </td>
        
                <td valign="top" class="name">
                    <label for="recordType"><g:message code="purchase.recordType" default="Record Type" />:</label>
                </td>
                <td valign="top" class="value ${hasErrors(bean: purchaseInstance, field: 'recordType', 'errors')}">
                    ${purchaseInstance?.recordType?.encodeAsHTML()}
                    <g:hiddenField name="recordType.id" value="${purchaseInstance?.recordType?.id}" />
                </td>
            </tr>
        
        </tbody>
    </table>
</div>
<div class="list">
    <table>
        <thead>
            <tr>
                <th><g:message code="purchaseDetail.serialNumber" default="Serial Number" /></th>
                <th><g:message code="purchaseDetail.product" default="Product" /></th>
                <th><g:message code="purchaseDetail.unit" default="Unit" /></th>
                <th class="number"><g:message code="purchaseDetail.quantity" default="Quantity" /></th>
                <th class="number"><g:message code="purchaseDetail.price" default="Price" /></th>
                <th class="number"><g:message code="purchaseDetail.amount" default="Amount" /></th>
             </tr>
        </thead>
        <tbody>
        <g:each in="${purchaseInstance?.details?.sort{it?.serialNumber}}" status="i" var="purchaseDetailInstance">
            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
                <td>
                    ${fieldValue(bean: purchaseDetailInstance, field: "serialNumber")}
                    <g:hiddenField name="details[${i}].serialNumber" value="${purchaseDetailInstance?.serialNumber}" />
                </td>
                <td>
                    ${fieldValue(bean: purchaseDetailInstance, field: "product")}
                    <g:hiddenField name="details[${i}].product.id" value="${purchaseDetailInstance?.product?.id}" />
                </td>
                <td>
                    ${fieldValue(bean: purchaseDetailInstance, field: "unit")}
                    <g:hiddenField name="details[${i}].unit" value="${purchaseDetailInstance?.unit}" />
                </td>
                <td class="number">
                    <g:textField name="details[${i}].quantity" value="${purchaseDetailInstance?.quantity}"/>
                </td>
                <td class="number">
                    <g:textField name="details[${i}].price" value="${purchaseDetailInstance?.price}"/>
                </td>
                <td class="number">
                    <span>
                        ${purchaseDetailInstance?.amount}
                    </span>
                    <g:hiddenField name="details[${i}].amount" value="${purchaseDetailInstance?.amount}"/>
                </td>
             </tr>
        </g:each>
        </tbody>
        <tfoot>
            <tr>
                <td></td>
                <td></td>
                <td></td>
                <td class="number">
                    <g:formatNumber number="${purchaseInstance.quantity}" format="###,##0.00"/>
                    <g:hiddenField name="purchaseInstance.quantity" value="${purchaseInstance?.quantity}"/>
                </td>
                <td></td>
                <td class="number">
                    <g:formatNumber number="${purchaseInstance.amount}" format="###,##0.00"/>
                    <g:hiddenField name="purchaseInstance.amount" value="${purchaseInstance?.amount}"/>
                </td>
            </tr>
        </tfoot>
     </table>
</div>

